﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace NSpotifyLib
{
    internal class ArtistReader : BaseReader<Artist>
    {
        internal ArtistReader(XDocument document) : base(document)
        {
        }

        public override IEnumerable<Artist> Read()
        {
            var artists = from artist in document.Descendants(ns + SpotifyTags.Artist)
                          select new Artist
                          {
                              Name = artist.Element(ns + SpotifyTags.Name).Value,
                              SpotifyLink = artist.Attribute(SpotifyTags.SpotifyLink) != null ? artist.Attribute("href").Value : String.Empty,
                              Popularity = Double.Parse(artist.Element(ns + SpotifyTags.Popularity).Value)
                          };

            return artists;
        }
    }
}
